package com.jzqf.harmonydemo.utils;

import ohos.app.Context;

/**
 * 应用崩溃异常处理
 *
 * @author LiuWeiHao
 * 2021/5/20 16:38
 */
public class CrashHandler {

    public static void init(Context context) {
        initCrash();
    }

    private static void initCrash() {
        Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
            throwable.printStackTrace();
            if (defaultUncaughtExceptionHandler != null) {
                defaultUncaughtExceptionHandler.uncaughtException(thread, throwable);
            } else {
                //TODO 杀死当前进程
                System.exit(1);
            }
        });
    }
}
